package com.ha8.netease.views.team.head
{
	import com.ha8.netease.App;
	import com.ha8.netease.PublicNotify;
	import com.ha8.netease.models.vo.ViewModel;
	import com.rogo.mvc.sub.mediator.Mediator;
	
	import flash.events.MouseEvent;
	
	/**
	 * 头部视图代理
	 * 
	 * @author rogo
	 */	
	public class HeadViewMediator extends Mediator
	{
		public function HeadViewMediator(viewComponent:Object)
		{
			super(NAME, viewComponent);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Constants
		//
		//--------------------------------------------------------------------------
		
		public static const NAME:String = 'headViewMediator';
		
		//--------------------------------------------------------------------------
		//
		//  Overridden Methods
		//
		//--------------------------------------------------------------------------
		
		override public function onRegister():void
		{
			updateDisplay();
			
			view.userImg.addEventListener(MouseEvent.CLICK, userImag_clickHandler);
			view.friendLab.addEventListener(MouseEvent.CLICK, friend_clickHandler);
			view.FanLab.addEventListener(MouseEvent.CLICK, FanLab_clickHandler);
			view.FavLab.addEventListener(MouseEvent.CLICK, FavLab_clickHandler);
			view.MainLab.addEventListener(MouseEvent.CLICK, MainLab_clickHandler);
			view.mailBtn.addEventListener(MouseEvent.CLICK, mailBtn_clickHandler);
			view.mentionBtn.addEventListener(MouseEvent.CLICK, mentionBtn_clickHandler);
			view.commentMe.addEventListener(MouseEvent.CLICK, commentMe_clickHandler);
		}
		
		//--------------------------------------------------------------------------
		//
		//  Methods
		//
		//--------------------------------------------------------------------------
		
		public function get view():HeadView
		{
			return viewComponent as HeadView;
		}
		
		/**
		 * 更新UI 
		 */		
		public function updateDisplay():void
		{
			view.userImg.source = App.getInstance().me.profile_image_url;
			view.userName.text = App.getInstance().me.name;
			view.friendLab.text = '关注' + App.getInstance().me.friends_count;
			view.FanLab.text = '粉丝' + App.getInstance().me.followers_count;
			view.FavLab.text = '收藏' + App.getInstance().me.favourites_count;
			view.MainLab.text = '微博' + App.getInstance().me.statuses_count;
		}
		
		//--------------------------------------------------------------------------
		//
		//  Event Handlers
		//
		//--------------------------------------------------------------------------
		
		private function userImag_clickHandler(e:MouseEvent):void
		{
			sendNotification(PublicNotify.DISPLAY_HOME_PAGE);
		}
		
		private function friend_clickHandler(e:MouseEvent):void
		{
			var model:ViewModel = new ViewModel();
			model.user = App.getInstance().me;
			model.type = ViewModel.FRIENDS;
			sendNotification(PublicNotify.DISPLAY_USER_PAGE, model);
		}
		
		private function FanLab_clickHandler(e:MouseEvent):void
		{
			var model:ViewModel = new ViewModel();
			model.user = App.getInstance().me;
			model.type = ViewModel.FANS;
			sendNotification(PublicNotify.DISPLAY_USER_PAGE, model);
		}
		
		private function FavLab_clickHandler(e:MouseEvent):void
		{
			var model:ViewModel = new ViewModel();
			model.user = App.getInstance().me;
			model.type = ViewModel.FAVORITE;
			sendNotification(PublicNotify.DISPLAY_MAIN_PAGE, model);
		}
		
		private function MainLab_clickHandler(e:MouseEvent):void
		{
			var model:ViewModel = new ViewModel();
			model.user = App.getInstance().me;
			model.type = ViewModel.MAIN;
			sendNotification(PublicNotify.DISPLAY_MAIN_PAGE, model);
		}
		
		private function mailBtn_clickHandler(e:MouseEvent):void
		{
			sendNotification(PublicNotify.DISPLAY_MAIL_PAGE);
		}
		
		private function mentionBtn_clickHandler(e:MouseEvent):void
		{
			var model:ViewModel = new ViewModel();
			model.user = App.getInstance().me;
			model.type = ViewModel.MENTION;
			sendNotification(PublicNotify.DISPLAY_MAIN_PAGE, model);
		}
		
		private function commentMe_clickHandler(e:MouseEvent):void
		{
			sendNotification(PublicNotify.DISPLAY_COMMENT_PAGE);
		}
		
	}
}